#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#include <immintrin.h>
//#include <emmintrin.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define fi first
#define se second
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=998244353;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
int _base=1;
inline int mol(const int x){return x-Mod*((__int128)_base*x>>64);}
inline void Add(int &x,const int y){x=mol(x+y);}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
	if(n<0){
		putchar('-');
		n*=-1;
	}
	if(n>9) print(n/10);
	putchar(n%10+'0');
}int n,m,k;
pair<int,int> r[N],b[N],a[N],gg[N];
int cnt,tot;
inline int calc(pair<int,int> x,pair<int,int> y){
	int res=0;
	if(x.fi<y.fi) res+=y.fi-x.fi;
	if(x.se<y.se) res+=y.se-x.se;
	return res;
}int dp[N];
signed main(){
	_base=((__int128)_base<<64)/Mod;
	freopen("move.in","r",stdin);
	freopen("move.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read(),m=read(),k=read();
	For(i,1,n) r[i]={read(),read()};
	For(i,1,m) b[i]={read(),read()};
	sort(r+1,r+n+1);sort(b+1,b+m+1);
	For(i,1,n) {
		while(cnt&&r[i].se>=a[cnt].se) cnt--;
		a[++cnt]=r[i];
	}
	if(k==1){
		memset(dp,0x3f,sizeof(dp));dp[0]=0;
		For(i,0,cnt){
			multiset<int>hi,ri,in;hi.clear(),ri.clear();in.clear();
			hi.insert(-1e16);ri.insert(-1e16);in.insert(-1e16);
			For(j,1,m) if(b[j].se>=a[i+1].se)hi.insert(b[j].fi);
					   else if(b[j].fi>=a[i+1].fi)ri.insert(b[j].se);
						else in.insert(b[j].fi+b[j].se);
			int t=0;
			For(j,1,m) if(b[j].fi>=a[i+1].fi){t=j;break;}
			For(j,i+1,cnt){
				while(t<=m&&b[t].fi<a[j].fi){
					if(ri.find(b[t].se)!=ri.end()){
						ri.erase(ri.lower_bound(b[t].se));
						in.insert(b[t].fi+b[t].se);
					}
					t++;
				}
				dp[j]=min(dp[j],dp[i]+min({a[j].fi-min(a[j].fi,*hi.rbegin()),a[j].fi+a[i+1].se-*in.rbegin(),a[i+1].se-min(a[i+1].se,*ri.rbegin())}));
			}
		}printf("%lld\n",dp[cnt]);
		return 0;
	}
	a[cnt+1]={1e16,1e16};int ans=0;
	Rof(i,cnt,1){tot=0;
		For(j,1,m){
			gg[++tot]={calc(b[j],a[i]),j};
		}sort(gg+1,gg+tot+1);
		For(j,1,k){
			ans+=gg[j].fi;
			int t=gg[j].se;
			if(b[t].fi<a[i].fi)b[t].fi=a[i].fi;
			if(b[t].se<a[i].se)b[t].se=a[i].se;
		}
	}
	printf("%lld\n",ans);
#ifdef LOCAL
	Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

